<%@ page contentType="text/html;charset=utf-8" language="java"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script type='text/javascript'
	src='<%=request.getContextPath()%>/dwr/interface/studentReportAction.js'></script>		
<script type='text/javascript'
	src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type='text/javascript'
	src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script type='text/javascript'
	src='<%=request.getContextPath()%>/js/jquery-latest.pack.js'></script>
<script type='text/javascript'
	src='<%=request.getContextPath()%>/js/noConflictOfJquery.js'></script>
<script type='text/javascript'
	src='<%=request.getContextPath()%>/js/page.js'></script>
<script type='text/javascript'>
var preasignid = "<%=session.getAttribute("studentPreAsignid")%>";
//登录者的学号
var studentNo = "<%=session.getAttribute("studentno")%>";
//若有集体申请者
var s0 = "${requestScope.studentno0}";
var s1 = "${requestScope.studentno1}";
var s2 = "${requestScope.studentno2}";
var s3 = "${requestScope.studentno3}";
var s4 = "${requestScope.studentno4}";
//此处原版dms里没有dormitorylodgetype字段，应换成dormitoryroomtype
var dormSql = "select d.dormitoryid as dormitoryid,"
	+"count(sbl.dormitorybedid) as inamout,"
	+"d.dormitorydisplayname as dormitorydisplayname,"
	+"d.dormitorylodgetype as dormitorylodgetype,"
	+"d.dormitorysex as dormitorysex from dormitory d"
	+" left join studentbedlink sbl on d.dormitoryid=sbl.dormitoryid"
	+" where d.allocationid="+preasignid+" and d.dormitoryind=1 group by d.dormitoryid"
	+" having inamout<d.dormitorylodgetype"
	+" order by d.dormitorysort";
$j(function(){
	//alert(dormSql);
	getAvailDorm(dormSql);
	//判断是否是集体申请
	if(s0 != '' || s1!= '' || s2 != '' || s3 != '' || s4 != ''){
		$j("#applyDorm").html('<button onclick="getMultiDorm()">集体申请</button>');
	}else{
		$j("#applyDorm").html('<button onclick="getSingleDorm()">申请宿舍</button>');
	}
	
	
});
function getAvailDorm(sql){
	studentReportAction.getAvailDormByPreAsignedid(sql,function(data){
		for(var a=0;a<data.length;a++){
			var datarow = data[a];
			var dormPicName = ""+datarow[4]+datarow[3]+datarow[1];
			//datarow[2]  :  3号楼 2层214a 房间
			//var tmp = datarow[2].split(" ");
			//displaynameInView : 3号楼214a
			var displaynameInView = datarow[2];
			//var displaynameInView = tmp[0] + (tmp[1].split("层"))[1];
			//document.writeln(displaynameInView);
			var	dormhtml='<div  style="float:left">'
					+ 	'<div>'
					+		'<img src="<%=request.getContextPath()%>/images/dormpic/'+dormPicName+'.jpg"'
					+ 		' id="'+datarow[0]+'" style="border:1px solid white" /></div>'
					+ 	' <div class="dormitoryinfo" >'+displaynameInView+'</div>'
					+ '</div>';
			$j("#dormShow").append(dormhtml);
		}
		
	
	});
	
}
//立即单人申请并获得宿舍
function getSingleDorm(){
	studentReportAction.singleApply(studentNo,function(msg){
		if("" != msg){
			alert(msg);
		}else {
			studentReportAction.findDormByStudentno(studentNo,function(data){
				//data[0] : dormitoryid
				//data[1] : dormitorydisplayname
				alert("您分配到的宿舍是:"+data[1]);
			});
		}
	});
	
}
//立即集体申请并获得宿舍
function getMultiDorm(){
	var stunos = studentNo;
	if("" != s0){
		stunos += (","+s0);
	}
	if("" != s1){
		stunos += (","+s1);
	}
	if("" != s2){
		stunos += (","+s2);
	}
	if("" != s3){
		stunos += (","+s3);
	}
	if("" != s4){
		stunos += (","+s4);
	}
	studentReportAction.multiApply(stunos,function(msg){
		if(msg = ""){
			alert("申请成功！");	
		}
				
	
	});
	
}
</script>
</head>
<body>
<div id="applyDorm"> 

</div>

<div id="dormShow">
</div>


</body>
</html>